// const baseUrl = 'https://asyk.nuofengtc.com';
// const baseUrl = 'http://192.168.2.14';
const baseUrl = 'https://dy.nuofenggr.com';
uni.setStorageSync('url',baseUrl)
function getRequest(url, data={}) {
	return new Promise((resolve, reject) => {
		uni.request({
			method: "GET",
			url: baseUrl + url,
			data,
			dataType: 'json',
			header: {
				// Authorization: 'Bearer '+uni.getStorageSync('token'),
				"content-type": "application/x-www-form-urlencoded",
				// token: uni.getStorageSync("aishang_token") ? uni.getStorageSync("aishang_token") : ""
				
			},
		}).then((response) => {
			let [error, res] = response;
			// 根据实际返回值设置未登录逻辑
			if(res.data.status == 301){
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
				setTimeout(()=>{
					// 未登录/登陆过期时的处理逻辑
					
				},1500)
			}else{
				resolve(res.data);
			}
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}

function postRequest(url, data={}) {
	return new Promise((resolve, reject) => {
		uni.request({
			method: "POST",
			url: baseUrl + url,
			data,
			dataType: 'json',
			header: {
				// Authorization: 'Bearer '+uni.getStorageSync('token'),
				"content-type": "application/x-www-form-urlencoded",
				// token: uni.getStorageSync("aishang_token") ? uni.getStorageSync("aishang_token") : "",
				
		
			},
		
		}).then((response) => {
			let [error, res] = response;
			// 根据实际返回值设置未登录逻辑
			if(res.data.status == 301){
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
				setTimeout(()=>{
					// 未登录/登陆过期时的处理逻辑
					
				},1500)
			}else{
				resolve(res.data);
			}
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}

export default {
	getRequest,
	postRequest,
	baseUrl
}
